// pages/transportPlan/transportPlan.ts
var url = require("../../utils/urls");
var commons = require("../../utils/common");
var tip = require("../../utils/tip");
var modelData = require("../../utils/data");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    // background: ['http://mtl-app.oss-cn-beijing.aliyuncs.com/upload/20221109/c190cf0161471594b5d0e8ad8967679b.webp'],
    bannerData: [],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
  },
  goWebView(e) {
    let data = e.currentTarget.dataset
    if (data.externalLinks) {
      wx.navigateTo({
        url: "../webView/webView?externalLinks=" + data.externalLinks
      })
    }
  },

  getBannerDetail: async function () {
    //planType  0:未完成计划 1：已完成计划  
    let requestUrl = url.getBannerDetail + "?type=1"

    let data = await commons.get(requestUrl);
    if (data.code == 200) {
      this.setData({
        bannerData: data.data
      })
      // console.log(this.data.bannerData, 'bannerData')
    } else {
      tip.showToast(data.msg, 'error', 1000)
    }
  },

  getDetailsInTransit: async function () {
    //planType  0:未完成计划 1：已完成计划  
    let requestUrl = url.fleetLeaderPlan + "?planType=0"
    let data = await commons.postJson(requestUrl);
    if (data.code == 200) {
      let resData = data.data
      resData.listPlanRespVOS.forEach((item, index) => {
        // item.vehicleFont = commons.getFont(modelData.vehicleType, item.vehicleType)
        item.transportedCount = commons.NumberSub(item.goodsPreviousCount, item.goodsSurplusCount)
        resData.listPlanRespVOS.splice(index, 1, item)
      });
      this.setData({
        list: resData.listPlanRespVOS
      })
    } else {
      tip.showToast(data.msg, 'error', 1000)
    }
  },

  goDispatch(e) {
    let item = e.currentTarget.dataset.item
    console.log(item)
    wx.navigateTo({
      url: "../dispatch/dispatch?item=" + JSON.stringify(item),
    })
  },
 //查看详情
  goTransportPlanDetail(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: "../transportPlanDetail/transportPlanDetail?item=" + JSON.stringify(item),
    })
  },
   //手动拼车调度
   goScheduling() {
    wx.navigateTo({
      url: "../scheduling/scheduling"
    })
  },
  //自动拼车调度
  goAutomaticScheduling() {
    let automatic = 'automatic'
    wx.navigateTo({
      url: "../scheduling/scheduling?automatic=" + automatic,
    })
  },
  //分享计划码
  shareView: function (e) {
    let planQrCode = e.currentTarget.dataset.item.planQrCode;
    planQrCode = planQrCode.replace('http', 'https');
    // let planQrCode ='http://mtl-app.oss-cn-beijing.aliyuncs.com/upload/20230524/59bb47593c2dd4122b0971b9e8fa94cd.png'
    wx.downloadFile({
      url: planQrCode,
      success: (res) => {
        console.log(res, 'resresresres');
        wx.showShareImageMenu({
          path: res.tempFilePath
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    let userInfo = wx.getStorageSync("userInfo");
    if (userInfo.roleAlias == 'boss') {
      wx.redirectTo(
        {
          url: "../management/management",
          fail(err) { console.log(err); }
        })
      return;
    }
    wx.showShareMenu({
      withShareTicket: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getBannerDetail()
    this.getDetailsInTransit()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getDetailsInTransit()
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {




  }
})
